﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO;
namespace DAO
{
   public  class LoaiTienDA
    {
       public static LoaiTien GetByID(int maID)
       {
           LoaiTien loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_LoaiTien_GetById", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(new SqlParameter("@maLoaiTien", maID));
           SqlDataReader dataReader = cmd.ExecuteReader();
           if (dataReader.Read())
           {
               loai = new LoaiTien();
               loai.MaLoaiTien= maID;
               loai.DelFlg = Convert.ToInt32(dataReader["DelFlg"]);
               loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
               loai.TenTien = Convert.ToString(dataReader["TenTien"]);
             }
           cn.Close();
           return loai;
       }
       public static List<LoaiTien> GetALL()
       {
           List<LoaiTien> lst = new List<LoaiTien>();
           LoaiTien loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_LoaiTien_GetALL", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataReader dataReader = cmd.ExecuteReader();
           while (dataReader.Read())
           {
               loai = new LoaiTien();
               loai.MaLoaiTien = Convert.ToInt32(dataReader["MaLoaiTien"]);
               loai.DelFlg = Convert.ToInt32(dataReader["DelFlg"]);
               loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
               loai.TenTien = Convert.ToString(dataReader["TenTien"]);
               lst.Add(loai);
           }
           cn.Close();
           return lst;
       }
    }
}
